package com.dwxt.community.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.community.admin.service.IntegralServiceAdmin;
import com.dwxt.community.entity.Information;
import com.dwxt.community.entity.IntegralRecord;
import com.dwxt.community.entity.IntegralRule;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/cms/integral")
@RestController
public class IntegralControllerAdmin {

    @Autowired
    private IntegralServiceAdmin integralServiceAdmin;

    @RequestMapping("/integralRecordPage")
    public BaseResult integralRecordPage(Integer pageNum, Integer pageSize, String userId) {
        PageHelper.startPage(pageNum, pageSize);
        List<IntegralRecord> integralRecordList = integralServiceAdmin.selectIntegralList(userId);
        PageInfo<IntegralRecord> pageInfo = new PageInfo<>(integralRecordList);
        return BaseResult.ok(pageInfo);
    }

    @RequestMapping("/selectAllRule")
    public BaseResult selectAllRule() {
        List<IntegralRule> ruleList = integralServiceAdmin.selectAllRule();
        return BaseResult.ok(ruleList);
    }

    @RequestMapping("/updateRule")
    public BaseResult updateRule(IntegralRule rule) {
        integralServiceAdmin.updateRule(rule);
        return BaseResult.ok();
    }


    @RequestMapping("/selectIntegralStatistics")
    public BaseResult selectIntegralStatistics() {
        return integralServiceAdmin.selectIntegralStatistics();
    }


    /**
     * 根据活动查询积分
     *
     * @return
     */
    @RequestMapping("/selectIntegralStatisticsByActive")
    public BaseResult selectIntegralStatisticsByActive() {
        return integralServiceAdmin.selectIntegralStatisticsByActive();
    }

    /**
     * 根据时间查积分
     *
     * @param year
     * @param month
     * @return
     */
    @RequestMapping("/selectIntegralStatisticsByTime")
    public BaseResult selectIntegralStatisticsByTime(Integer year, Integer month) {
        return integralServiceAdmin.selectIntegralStatisticsByTime(year, month);
    }

    /**
     * 根据电话查询积分
     *
     * @param phone
     * @return
     */
    @RequestMapping("/selectIntegralStatisticsByUser")
    public BaseResult selectIntegralStatisticsByUser(String phone,Integer pageNum, Integer pageSize,Integer orderType,
                                                     String sequence) {
        return integralServiceAdmin.selectIntegralStatisticsByUser(phone,pageNum,pageSize,orderType,sequence);
    }

    @RequestMapping("export")
    public void export(Integer type, Integer year, Integer month, String phone, HttpServletResponse response) {
        integralServiceAdmin.export(type,year,month,phone,response);
    }

}
